package com.xiang.mall.framework.core.utils

import com.xiang.mall.framework.base.exception.BaseException
import org.springframework.beans.BeanUtils
import kotlin.reflect.KClass

/**
 * @author xiangliyou
 * @email xiangliyou1814@mail.yneusoft.com
 * @date 2019-03-06 15:15
 *
 */
object BeanUtilsEx {
    @JvmStatic
    fun <T : Any> copyProperties(source: Any, targetClazz: KClass<T>): T {
        val target = targetClazz.objectInstance
            ?: throw BaseException("bean 类型转换失败,请检查 target 目标类的定义,可能是缺失默认构造函数")
        BeanUtils.copyProperties(source, target)
        return target
    }
}